package com.terabits.smartriver.controller;

import com.alibaba.fastjson.JSONArray;
import com.terabits.smartriver.constants.result.BaseResp;
import com.terabits.smartriver.constants.result.ResultStatus;
import com.terabits.smartriver.meta.vo.PaperVO;
import com.terabits.smartriver.meta.po.InspectionPaper;
import com.terabits.smartriver.meta.po.InspectionTopic;
import com.terabits.smartriver.service.InspectioService;
import com.terabits.smartriver.util.PageData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 点检接口
 */
@CrossOrigin
@RestController
public class InspectionController extends BaseController {
    @Autowired
    private InspectioService inspectioService;

    @ApiOperation(value = "查看所有点检题目", tags = {"系统管理-点检题库"})
    @RequestMapping(value = "/system-mgt/inspection/topic/get", method = RequestMethod.GET)
    public BaseResp getTopic() {
        return new BaseResp(ResultStatus.SUCCESS, inspectioService.getTopic(this.getPageData()));
    }

    @ApiOperation(value = "删除题目", tags = {"设备管理-设备点检"})
    @RequestMapping(value = "/device-mgt/inspection/topic/delete", method = RequestMethod.POST)
    public BaseResp deleteTopics(Integer id) {
        return new BaseResp(ResultStatus.SUCCESS, inspectioService.deleteTopics(id));
    }

    @ApiOperation(value = "出题", tags = {"系统管理-点检题库"})
    @RequestMapping(value = "/system-mgt/inspection/topic/add", method = RequestMethod.POST)
    public BaseResp addTopic(@RequestParam(value = "topicsJSON") String topicsJSON) {
        List<InspectionTopic> topics = JSONArray.parseArray(topicsJSON, InspectionTopic.class);
        inspectioService.addTopics(findCurrentUser().getId(), topics);
        return new BaseResp(ResultStatus.SUCCESS);
    }

    @ApiOperation(value = "设备点检 查找卷", tags = {"设备管理-设备点检"})
    @RequestMapping(value = "/device-mgt/inspection/paper/get", method = RequestMethod.GET)
    public BaseResp getInspectionPaper() {
        List<PaperVO> papers = inspectioService.getPaper(this.getPageData());
        return new BaseResp(ResultStatus.SUCCESS, papers);
    }

    @ApiOperation(value = "设备点检 生成卷", tags = {"设备管理-设备点检"})
    @RequestMapping(value = "/device-mgt/inspection/paper/add", method = RequestMethod.POST)
    public BaseResp addInspectionPaper(InspectionPaper inspectionPaper) {
        inspectionPaper.setUserId(findCurrentUser().getId());
        return new BaseResp(ResultStatus.SUCCESS, inspectioService.addPaper(inspectionPaper));
    }

    @ApiOperation(value = "设备点检 修改卷 其实就是绑定设备", tags = {"设备管理-设备点检"})
    @RequestMapping(value = "/device-mgt/inspection/paper/update", method = RequestMethod.POST)
    public BaseResp updateInspectionPaper(InspectionPaper inspectionPaper) {
        inspectionPaper.setUserId(findCurrentUser().getId());
        return new BaseResp(ResultStatus.SUCCESS, inspectioService.updatePaper(inspectionPaper));
    }

    @ApiOperation(value = "设备点检 删除卷 其实就是绑定设备", tags = {"设备管理-设备点检"})
    @RequestMapping(value = "/device-mgt/inspection/paper/delete", method = RequestMethod.POST)
    public BaseResp deleteInspectionPaper(Integer id) {
        return new BaseResp(ResultStatus.SUCCESS, inspectioService.deletePaper(id));
    }

    @ApiOperation(value = "设备点检记录 查看", tags = {"设备管理-设备状态"})
    @RequestMapping(value = "/device-mgt/device/inspection-result/get", method = RequestMethod.GET)
    public BaseResp getInspectionResult() {
        List<PageData> results = inspectioService.getResult(this.getPageData());
        return new BaseResp(ResultStatus.SUCCESS, results);
    }


}
